Jyro Visual SimulatorΒΆ

This notebook demonstrates creating a visual simulation of the Pioneer robot from MobileRobots.

Here is a picture of the Pioneer robot:

First, we import the items that we will need:

In [1]:
from jyro.simulator import *
import math

We create a Pioneer robot by giving it a name, x-coordinate, y-coordinate, and a facing angle in radians. The coordinates are given in meters.

In [2]:
robot = Pioneer("Pioneer", 2.50, 4.50, math.pi * 3/2) # meters, radians

To see a top-down view of the robot in the notebook:

In [3]:
robot
Out[3]:
_images/Visual_Simulator_7_0.svg

Next, we add some devices to the Pioneer, including sonar sensors, light sensors, a camera, and a gripper.

In [4]:
robot.addDevice(Pioneer16Sonars())
Out[4]:
_images/Visual_Simulator_9_0.svg
In [5]:
robot.addDevice(PioneerFrontLightSensors())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-4bc1997da056> in <module>()
----> 1 robot.addDevice(PioneerFrontLightSensors())

TypeError: __init__() missing 1 required positional argument: 'maxRange'
In [6]:
robot.addDevice(Camera(120, 80))
Out[6]:
_images/Visual_Simulator_11_0.svg
In [7]:
robot.addDevice(Gripper())
Out[7]:
_images/Visual_Simulator_12_0.svg

Finally, we create a world function that takes a simulator and adds items to the world:

In [8]:
def world(sim):
    sim.addBox(0, 0, 5, 5, fill="backgroundgreen", wallcolor="lightgrey") # meters
    sim.addBox(1, 1, 2, 2, "purple")
    sim.addLight(4, 4, 2.25, color=Color(255, 255, 0, 64))

To create a visual simulation, pass in the robot and the world function. Optionally, you can set gamepad=True to control the robot with a gamepad.

In [9]:
VSimulator(robot, world, gamepad=True);
In [14]:
robot.brain = lambda self: self.move(1,-1)
In [15]:
robot.getPose()
Out[15]:
(2.5, 4.5, 4.71238898038469)

If you are viewing (rather than executing) this notebook, then the above simulation looks like this:

In [16]:
sim = Simulator(robot, world, gamepad=True)
0.00 seconds
    Pioneer: (2.5, 4.5, 4.71238898038469)
In [17]:
sim.step(1.70)
1.70 seconds
    Pioneer: (3.547280510061178, 3.421679606793642, 3.0123889803846913)